﻿using System.Collections.Generic;
using System.Data;
using System;
using ZHDJ.MobileInterface.Common;
using SXT.Party.Law.Model;


/*点评律师*/
namespace ZHDJ.MobileInterface
{
    public partial class ToCommentLawyer : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            ToCommentLawyerOutParam result = new ToCommentLawyerOutParam();
            ToCommentLawyerInParam param = new ToCommentLawyerInParam();
            string logMsg = "";
            bool isFlag = true;

            try
            {
                param = inParam as ToCommentLawyerInParam;

                if (param.Type == "1")
                {
                    #region 评价用户
                    if (string.IsNullOrEmpty(param.LawyerID))
                    {
                        result.code = "0";
                        result.desc = "律师ID不能为空";

                        isFlag = false;
                    }

                    if (string.IsNullOrEmpty(param.CreateBy))
                    {
                        result.code = "0";
                        result.desc = "评价人ID不能为空";

                        isFlag = false;
                    }
                    if(string.IsNullOrEmpty(param.Content))
                    {
                        result.code = "0";
                        result.desc = "评价内容不能为空";

                        isFlag = false;
                    }
                    if (isFlag)
                    {
                        PartyLawEvaluation FA = new PartyLawEvaluation();
                        FA.EvaluationID = StringHelper.NewID;
                        FA.Load();
                        FA.Content = param.Content;
                        FA.CreateBy = param.CreateBy;
                        FA.CreateTime = DateTime.Now;
                        FA.Lawyer = param.LawyerID;
                        FA.Level = param.Level;
                        FA.ScoreBusinessLevel = param.ScoreBusinessLevel;
                        FA.ScoreReplyspeed = param.ScoreReplyspeed;
                        FA.WorkingAttitude = param.WorkingAttitude;

                        result.desc = PartyLawEvaluation.AddEvaluation(FA, param.CreateBy, "Mobile");
                    }
                    #endregion
                }
                else if (param.Type == "2")
                {
                    #region 点赞评论
                    
                    if (string.IsNullOrEmpty(param.CreateBy))
                    {
                        result.code = "0";
                        result.desc = "点赞人ID不能为空";

                        isFlag = false;
                    }
                    if (string.IsNullOrEmpty(param.ConsultationID))
                    {
                        result.code = "0";
                        result.desc = "咨询ID不能为空";

                        isFlag = false;
                    }
                    DataTable dt = PartyLawConsultation.GetConsultationBy(param.ConsultationID).Tables[0];
                    if (isFlag)
                    {
                        
                        if(dt.Rows.Count!=1)
                        {
                            result.code = "0";
                            result.desc = "咨询ID不存在，请确认！。";

                            isFlag=false;

                        }}
                    if (isFlag)
                    {
                        if (dt.Rows[0]["ConsultationBy"].ToString() != param.CreateBy)
                        {
                            result.code = "0";
                            result.desc = "点赞人必须为当前咨询人。";

                            isFlag = false;
                        }
                    }
                    if (isFlag)
                    {
                        if (dt.Rows[0]["DianZan"].ToString() == "True")
                        {
                            result.code = "0";
                            result.desc = "该咨询已经点赞，不能多次点赞。";

                            isFlag = false;
                        }
                        //FF.DianZan = true;                        
                    }
                    if (isFlag)
                    {
                        result.desc = PartyLawConsultation.AddConsultationDianZan(param.ConsultationID);
                    }
                    #endregion
                }
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "转移过程出现异常，多次出现请联系管理员";
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode + "-ToCommentLawyer", SerializeHelper.JsonSerializer<ToCommentLawyerInParam>(param), logMsg);
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<ToCommentLawyerInParam, ToCommentLawyerOutParam>();
            else
                SafeProcessRequest<ToCommentLawyerInParam, ToCommentLawyerOutParam>();
        }

    }

    #region 请求参数
    public class ToCommentLawyerInParam
    {
        /// <summary>
        /// 律师
        /// </summary>
        public string LawyerID { get; set; }

        /// <summary>
        /// 回复速度
        /// </summary>
        public double ScoreReplyspeed { get; set; }

        /// <summary>
        /// 业务水平
        /// </summary>
        public double ScoreBusinessLevel { get; set; }

        /// <summary>
        /// 工作态度
        /// </summary>
        public double WorkingAttitude { get; set; }

        /// <summary>
        /// 评价内容
        /// </summary>
        public string Content { get; set; }

        /// <summary>
        /// 评价  1-好评  2-中评  3-差评
        /// </summary>
        public int Level { get; set; }

        /// <summary>
        /// 评价人
        /// </summary>
        public string CreateBy { get; set; }

        /// <summary>
        /// 类型
        /// </summary>
        public string Type { get; set; }

        /// <summary>
        /// 咨询ID
        /// </summary>
        public string ConsultationID { get; set; }




    }
    #endregion

    #region 结果参数
    public class ToCommentLawyerOutParam
    {
        public ToCommentLawyerOutParam()
        {
            code = "1";
            desc = "操作成功";
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }
    }
    #endregion
}